package group.raber.saber.jdbc.accessor;

import group.raber.saber.jdbc.accessor.listener.DeleteListener;
import group.raber.saber.jdbc.accessor.listener.InsertListener;
import group.raber.saber.jdbc.accessor.listener.UpdateListener;

import java.util.List;
import java.util.Map;

/**
 * 数据访问器,主要完简单数据的增,删,改操作
 * Created by tisir<yangsong158@qq.com> on 2017-06-02
 */
public interface DataAccessor{

    public <T> T selectOne(Class<T> classType,String sql,Map<String,Object> parameter);
    public <T> List<T> selectList(Class<T> classType,String sql,Map<String,Object> parameter);
    public Integer selectForInt(String sql, Map<String,Object> parameter);
    public Integer selectForInt(String sql, String k1, Object v1);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8);
    public Integer selectForInt(String sql, String k1, Object v1, String k2, Object v2, String k3, Object v3, String k4, Object v4, String k5, Object v5, String k6, Object v6, String k7, Object v7, String k8, Object v8, String k9, Object v9);


    /** ============================================ **/
    /** 以下是工具化查询,提供快速工具,最多支持9对参数的查询 **/
    /** ============================================ **/

    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6,String k7,Object v7);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6,String k7,Object v7,String k8,Object v8);
    public <T> T selectOne(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6,String k7,Object v7,String k8,Object v8,String k9,Object v9);

    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6,String k7,Object v7);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6,String k7,Object v7,String k8,Object v8);
    public <T> List<T> selectList(Class<T> classType,String sql,String k1,Object v1,String k2,Object v2,String k3,Object v3,String k4,Object v4,String k5,Object v5,String k6,Object v6,String k7,Object v7,String k8,Object v8,String k9,Object v9);


    /** ============================================ **/
    /**       以下是对JavaBean的数据库常用的CRDU操      **/
    /** ============================================ **/

    public <T> int insert(T entity);
    public <T> int insert(T entity, InsertListener<T> listener);
    public <T> int update(T entity);
    public <T> int update(T entity, UpdateListener<T> listener);
    public <T> int save(T entity);
    public <T> int save(T entity, InsertListener<T> insertListener, UpdateListener<T> updateListener);
    public <T> int delete(T entity);
    public <T> int delete(T entity, DeleteListener<T> listener);

    public <T> int insert(String table,T entity);
    public <T> int insert(String table,T entity, InsertListener<T> listener);
    public <T> int update(String table,T entity);
    public <T> int update(String table,T entity, UpdateListener<T> listener);
    public <T> int save(String table,T entity);
    public <T> int save(String table,T entity, InsertListener<T> insertListener, UpdateListener<T> updateListener);
    public <T> int delete(String table,T entity);
    public <T> int delete(String table,T entity, DeleteListener<T> listener);

    public <T> int insert(List<T> entityList);
    public <T> int insert(List<T> entityList, InsertListener<List<T>> listener);
    public <T> int update(List<T> entityList);
    public <T> int update(List<T> entityList, UpdateListener<List<T>> listener);
    public <T> int save(List<T> entityList);
    public <T> int save(List<T> entityList, InsertListener<List<T>> insertListener, UpdateListener<List<T>> updateListener);
    public <T> int delete(List<T> entityList);
    public <T> int delete(List<T> entityList, DeleteListener<List<T>> listener);

    public <T> int insert(String table,List<T> entityList);
    public <T> int insert(String table,List<T> entityList, InsertListener<List<T>> listener);
    public <T> int update(String table,List<T> entityList);
    public <T> int update(String table,List<T> entityList, UpdateListener<List<T>> listener);
    public <T> int save(String table,List<T> entityList);
    public <T> int save(String table,List<T> entityList, InsertListener<List<T>> insertListener, UpdateListener<List<T>> updateListener);
    public <T> int delete(String table,List<T> entityList);
    public <T> int delete(String table,List<T> entityList, DeleteListener<List<T>> listener);

    /** ============================================ **/
    /**           以下是对Map的数据库常用的CRDU操       **/
    /** ============================================ **/

    public int insertMap(String table,Map<String,Object> entity);
    public int insertMap(String table,Map<String,Object> entity,InsertListener<Map<String,Object>> listener);
    public int updateMap(String table,Map<String,Object> entity,Map<String,Object> keyAttributes);
    public int updateMap(String table,Map<String,Object> entity,Map<String,Object> keyAttributes,UpdateListener<Map<String,Object>> listener);
    public int saveMap(String table,Map<String,Object> entity,Map<String,Object> keyAttributes);
    public int saveMap(String table,Map<String,Object> entity,Map<String,Object> keyAttributes,InsertListener<Map<String,Object>> insertListener,UpdateListener<Map<String,Object>> updateListener);
    public int deleteMap(String table,Map<String,Object> keyAttributes);
    public int deleteMap(String table,Map<String,Object> keyAttributes,DeleteListener<Map<String,Object>> listener);

    public int insertMap(String table,List<Map<String,Object>> entityList);
    public int insertMap(String table,List<Map<String,Object>> entityList,InsertListener<List<Map<String,Object>>> listener);
    public int updateMap(String table,List<Map<String,Object>> entityList,List<Map<String,Object>> keyAttributesList);
    public int updateMap(String table,List<Map<String,Object>> entityList,List<Map<String,Object>> keyAttributesList,UpdateListener<List<Map<String,Object>>> listener);
    public int saveMap(String table,List<Map<String,Object>> entityList,List<Map<String,Object>> keyAttributesList);
    public int saveMap(String table,List<Map<String,Object>> entityList,List<Map<String,Object>> keyAttributesList,InsertListener<List<Map<String,Object>>> insertListener,UpdateListener<List<Map<String,Object>>> updateListener);
    public int deleteMap(String table,List<Map<String,Object>> keyAttributesList);
    public int deleteMap(String table,List<Map<String,Object>> keyAttributesList,DeleteListener<List<Map<String,Object>>> listener);

}
